﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using TeachingManageSystem.DAL;
using TeachingManageSystem.Entity;

namespace TeachingManageSystem.BLL
{
     public class UsersBll:DBHelper
     {
         #region 添加用户信息
         /// <summary>
         /// 添加用户信息
         /// </summary>
         /// <param name="user"></param>
         /// <returns></returns>
         public static int InsertUsers(User user)
         {
             var sqlParameters = new SqlParameter[3];
             sqlParameters[0] = MakeInParam("@num", SqlDbType.Int, 50, user.UserNum);
             sqlParameters[1] = MakeInParam("@name", SqlDbType.NVarChar, 50, user.Name);
             sqlParameters[2] = MakeInParam("@usertypeid", SqlDbType.Int, 50, user.UsersTypeID);
             return ProManageData("InsertUsers", sqlParameters);
         }
         #endregion

         #region 获取所有用户信息
         /// <summary>
         /// 
         /// </summary>
         /// <returns></returns>
         public static DataSet GetAllUsers()
         {
             return ProGetData("SelectAllUsers", null);
         }
         #endregion

         #region 删除用户信息
         /// <summary>
         /// 
         /// </summary>
         /// <param name="usersid"></param>
         /// <returns></returns>
         public static int DeleteUsersByID(int usersid)
         {
             var sqlParamters = new SqlParameter[1];
             sqlParamters[0] = MakeInParam("@id", SqlDbType.Int, 20, usersid);
             return ProManageData("DeleteUsersByID", sqlParamters);
         }
         #endregion

         #region  根据用户ID更新用户信息（管理员操作）
         /// <summary>
         /// 
         /// </summary>
         /// <param name="user"></param>
         /// <returns></returns>
         public static int UpdateUsersByID(User user)
         {
             var sqlParameters = new SqlParameter[4];
             sqlParameters[0] = MakeInParam("@id", SqlDbType.Int, 20, user.ID);
             sqlParameters[1] = MakeInParam("@num", SqlDbType.NVarChar, 50, user.UserNum);
             sqlParameters[2] = MakeInParam("@name", SqlDbType.NVarChar, 100, user.Name);
             sqlParameters[3] = MakeInParam("@usertypeid", SqlDbType.NVarChar, 100, user.UsersTypeID);
             return ProManageData("UpdateUsersByID", sqlParameters);
         }
         #endregion
     }
}
